package demo.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

public class StarPane extends JPanel implements MouseListener{
	
	ArrayList<Point> lst = new ArrayList<Point>();
	int R = 30;
	ArrayList<Point> temp = new ArrayList<Point>();
	
	public StarPane(){
		super();
		this.addMouseListener(this);
		temp.add(new Point(0, 0));
		temp.add(new Point(0, 0));
		temp.add(new Point(0, 0));
		temp.add(new Point(0, 0));
		temp.add(new Point(0, 0));
	}
	
	double PIC2 = Math.PI/2; 
	double P2C5 = 2*Math.PI/5;
	
    @Override
    public void paintComponent(Graphics g) {
    	double alp = 0;
    	double x, y;
        super.paintComponent(g);
        for(int i=0; i<lst.size(); i++){
        	for(int k=0; k<5; k++){
        		alp = PIC2 + k * P2C5;
        		x = lst.get(i).x + 100 * Math.cos(alp);
				y = lst.get(i).y + 100 * Math.sin(alp);
				temp.get(k).x = (int)x;
				temp.get(k).y = (int)y;
				//temp.add(new Point((int)x, (int)y));
				
				//System.out.println("paint: " + alp + ", (" + x + ", " + y + ")");
        	}
        	g.drawLine(temp.get(0).x, temp.get(0).y, temp.get(2).x, temp.get(2).y);
        	g.drawLine(temp.get(0).x, temp.get(0).y, temp.get(3).x, temp.get(3).y);
        	g.drawLine(temp.get(1).x, temp.get(1).y, temp.get(4).x, temp.get(4).y);
        	g.drawLine(temp.get(1).x, temp.get(1).y, temp.get(3).x, temp.get(3).y);
        	g.drawLine(temp.get(2).x, temp.get(2).y, temp.get(4).x, temp.get(4).y);
        }
    }

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		lst.add(new Point(e.getX(), e.getY()));
		System.out.println(e.getX() + ", " + e.getY());
		this.repaint();
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}